package com.fmsz.xmly.adapters.classify;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.fmsz.xmly.activitys.classify.ClassifyFocusImageActivity;
import com.squareup.picasso.Picasso;

/**
 * Created by Administrator on 2016/12/3.
 */

public class FindClassifyPagerAdapter extends PagerAdapter{

    private ImageView[] images;
    private String[] imageUrls;
    private Context context;
    private String[] htmlUrls;

    public FindClassifyPagerAdapter(Context context, ImageView[] images, String[] imageUrls,String[] htmlUrls) {
        this.context = context;
        this.images = images;
        this.imageUrls = imageUrls;
        this.htmlUrls = htmlUrls;
    }

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(images[position]);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        images[position].setScaleType(ImageView.ScaleType.FIT_XY);
        images[position].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ClassifyFocusImageActivity.class);
                intent.putExtra("htmlUrl",htmlUrls[position]);
                context.startActivity(intent);
            }
        });
        container.addView(images[position]);
        Picasso.with(context).load(imageUrls[position]).into(images[position]);
        return images[position];
    }

}
